export function getConfig(target, configs, assets, onNodeCreate) {
  const title = configs.title,
        search = configs.search,
        options = configs.options;
  return {
    title,
    target,
    animation: false,
    validateNode: node => {
      onNodeCreate && onNodeCreate(node);
      return false;
    },
    getDragNode: node => {
      const _node$data = node.data,
            value = _node$data.value,
            moduleType = _node$data.moduleType,
            moduleImage = _node$data.moduleImage;
      const image = assets[moduleImage] || assets[`${moduleType ? moduleType : value}Module`] || moduleImage;
      return target.createNode({
        shape: 'lane-node',
        label: node.label,
        data: node.data,
        attrs: {
          body: {
            fill: '#ccc'
          },
          itemTag: {
            xlinkHref: image
          },
          backgorund: {
            xlinkHref: assets['innerSystem']
          }
        }
      });
    },
    search: (cell, keyword) => {
      if (keyword) {
        return cell.shape === 'moduleNode' && `${cell.attr('text/text')}`.toLowerCase().includes(`${keyword}`.toLowerCase());
      }

      return true;
    },
    placeholder: (search === null || search === void 0 ? void 0 : search.placeholder) || '请输入组件名称',
    stencilGraphWidth: 200,
    collapsable: false,
    groups: options.map(({
      label,
      value,
      children
    }) => ({
      title: label,
      name: value,
      collapsable: false,
      graphPadding: 0,
      graphHeight: (Array.isArray(children) ? children.length * 32 : 0) + 10,
      layoutOptions: {
        columns: 1,
        columnWidth: 190,
        rowHeight: 32,
        dx: 5,
        dy: 5
      }
    }))
  };
}
export function appendOptions(graph, stencil, options, assets) {
  const moduleProps = {};
  const modules = {};
  options.forEach(group => {
    const groupName = group.value,
          children = group.children;
    if (!Array.isArray(children)) return;
    const items = children.map(item => {
      const label = item.label,
            value = item.value,
            icon = item.icon,
            moduleType = item.moduleType,
            moduleProp = item.moduleProp;
      moduleProps[moduleType || value] = moduleProp;
      modules[moduleType || value] = item;
      delete item.moduleProp;
      const image = assets[`${icon}Icon`] || icon;
      item.moduleType = moduleType || value;
      const node = graph.createNode({
        shape: 'moduleNode',
        label,
        data: item
      });
      node.attr('icon/xlinkHref', image);
      return node;
    });
    stencil.load(items, groupName);
  });
  window._moduleProps = moduleProps;
  window._modules = modules;
}